home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / cport1.zip / CPORT.H < prev    next >
Text File  |  1991-06-03  |  7KB  |  278 lines

  1. /* 
  2. ** CPORT.H    
  3. ** Header file for Cport Serial Communications Library
  4. **
  5. ** Copyright (c) 1991 Bri Productions
  6. **
  7. */
  8.  
  9. #if defined  __TURBOC__
  10. #if  __STDC__
  11. #define  _Cdecl
  12. #else
  13. #define  _Cdecl  cdecl
  14. #endif
  15. #elif defined  __ZTC__
  16. #define  _Cdecl
  17. #elif defined  M_I86 && !defined  __ZTC__  
  18. #if !defined NO_EXT_KEYS
  19. #define  _Cdecl  cdecl
  20. #else
  21. #define  _Cdecl
  22. #endif
  23. #endif
  24.  
  25.  
  26.  
  27. /*
  28. **-------------------------------------
  29. **
  30. ** com ports 
  31. **
  32. **-------------------------------------
  33. */
  34. #define  COM1  0xC3F8            /* vector = 0xC, port base = 0x3F8  */
  35. #define  COM2  0xB2F8            /* vector = 0xB, port base = 0x2F8  */
  36. #define  COM3  0xC3E8            /* vector = 0xC, port base = 0x3E8  */
  37. #define  COM4  0xB2E8            /* vector = 0xB, port base = 0x2E8  */
  38.  
  39.  
  40. /*
  41. **-------------------------------------
  42. **
  43. ** baud rate divisors 
  44. **
  45. **-------------------------------------
  46. */
  47. #define  B115200  1
  48. #define  B57600   2
  49. #define  B38400   3
  50. #define  B19200   6
  51. #define  B9600    12
  52. #define  B7200    16
  53. #define  B4800    24
  54. #define  B3600    32
  55. #define  B2400    48
  56. #define  B2000    58
  57. #define  B1800    64
  58. #define  B1200    96
  59. #define  B600     192
  60. #define  B300     384
  61. #define  B150     768
  62. #define  B110     1047
  63. #define  B75      1536
  64. #define  B50      2304
  65.  
  66.  
  67. /*
  68. **-------------------------------------
  69. **
  70. ** word lengths 
  71. **
  72. **-------------------------------------
  73. */
  74. #define  W8    3
  75. #define  W7    2
  76. #define  W6    1
  77. #define  W5    0
  78. #define  WMASK 3
  79.  
  80. /*
  81. **-------------------------------------
  82. **
  83. ** stop bits 
  84. **
  85. **-------------------------------------
  86. */
  87. #define  S1    0
  88. #define  S2    4
  89. #define  SMASK 1
  90.  
  91.  
  92. /*
  93. **-------------------------------------
  94. **
  95. ** parity 
  96. **
  97. **-------------------------------------
  98. */
  99. #define  NONE     0x00
  100. #define  ODD      0x08
  101. #define  EVEN     0x18
  102. #define  MARK     0x28
  103. #define  SPACE    0x38
  104. #define  PMASK    0x38
  105.  
  106.  
  107. /*
  108. **-------------------------------------
  109. **
  110. ** handshaking
  111. **
  112. **-------------------------------------
  113. */
  114. #define  SOFT  1
  115. #define  HARD  2
  116.  
  117.  
  118. /*
  119. **-------------------------------------
  120. **
  121. ** error codes
  122. **
  123. **-------------------------------------
  124. */
  125. #define  OVERUN    0x002         /* overrun error           */
  126. #define  PARITY    0x004         /* parity error            */
  127. #define  FRAMING   0x008         /* framing error           */
  128. #define  BREAK     0x010         /* break detect            */
  129. #define  TXFULL    0x100         /* transmit queue overflow */
  130. #define  RXFULL    0x200         /* receive queue overflow  */
  131.  
  132.  
  133. /*
  134. **-------------------------------------
  135. **
  136. ** status codes
  137. **
  138. **-------------------------------------
  139. */
  140. #define  DCTS  0x01           /* delta clear to send           */
  141. #define  DDSR  0x02           /* delta data set ready          */
  142. #define  TERI  0x04           /* trailing edge ring  indicator */
  143. #define  DDCD  0x08           /* delta data carrier detect     */
  144. #define  CTS   0x10           /* clear to send                 */
  145. #define  DSR   0x20           /* data set ready                */
  146. #define  RI    0x40           /* ring indicator                */
  147. #define  DCD   0x80           /* data carrier detect           */
  148.  
  149.  
  150. /*
  151. **-------------------------------------
  152. **
  153. ** byte typedef and parameter structure
  154. **
  155. **-------------------------------------
  156. */
  157. #ifndef BYTE
  158. #define BYTE
  159. typedef unsigned char byte;   
  160. #endif
  161.  
  162.    /** Do not change this structure **/
  163.  
  164. struct C_param{               
  165.    unsigned com;              /* com port                         */
  166.    int      baud;             /* baud rate                        */
  167.    byte     mode;             /* word length, stop bits, parity   */
  168.    unsigned rxQ;              /* receive queue size               */
  169.    unsigned txQ;              /* transmit queue size              */
  170.    byte     htype;            /* handshaking type                 */
  171.    unsigned thresh;           /* handshaking threshold (rx queue) */
  172.    };
  173.  
  174.  
  175. /*
  176. **-------------------------------------
  177. **
  178. ** some other constants 
  179. **
  180. **-------------------------------------
  181. */
  182. #define  ON    1
  183. #define  OFF   0
  184.  
  185.  
  186. /*
  187. **-------------------------------------
  188. **
  189. ** ComOpen return codes 
  190. **
  191. **-------------------------------------
  192. */
  193. #define  NO_ERR    0        /* no error                         */
  194. #define  OPENED    1        /* port already open                */
  195. #define  BAD_COM   2        /* bad 'com' parameter              */
  196. #define  NO_UART   3        /* no uart chip found               */
  197. #define  RCV_ALC   4        /* receive queue allocation error   */
  198. #define  TX_ALC    5        /* transmit queue allocation error  */
  199.  
  200.  
  201. /*
  202. **-------------------------------------
  203. **
  204. ** function macros 
  205. **
  206. **-------------------------------------
  207. */
  208. #define  ComOut1(a)           ComMcr(a, 0x04)   
  209. #define  ComRts(a)            ComMcr(a, 0x02)   
  210. #define  ComDtr(a)            ComMcr(a, 0x01)   
  211. #define  ComReopen(a,b,c,d,e) ComOpen(a,b,c,d,e)
  212.  
  213.  
  214. /*
  215. **-------------------------------------
  216. **
  217. ** function prototypes 
  218. **
  219. **-------------------------------------
  220. */
  221.  
  222.    /* control functions */
  223.  
  224. int      _Cdecl   ComOpen        (unsigned com, int baud, byte mode, unsigned rxQ, unsigned txQ);  
  225. int      _Cdecl   ComOpenS       (const struct C_param *param);
  226. void     _Cdecl   ComParam       (const struct C_param *param);
  227. void     _Cdecl   ComClose       (void);                    
  228. void     _Cdecl   ComBaud        (int baud);
  229. void     _Cdecl   ComMode        (byte mode);
  230. void     _Cdecl   ComHandshake   (byte htype, unsigned thresh);
  231. void     _Cdecl   ComTx          (byte on_off);
  232.  
  233.  
  234.    /* input functions    */
  235.  
  236. char     _Cdecl   ComGetc        (void);                        
  237. char    *_Cdecl   ComGets        (char *str, int max_c, char term_c);     
  238. unsigned _Cdecl   ComIn          (void *abyte, unsigned n_byte); 
  239. char     _Cdecl   ComPeek        (void);
  240. unsigned _Cdecl   ComLenRx       (void);                       
  241. void     _Cdecl   ComFlushRx     (void);                       
  242.  
  243.  
  244.    /* output functions  */
  245.  
  246. int      _Cdecl   ComPutc        (char c);                      
  247. int      _Cdecl   ComPuts        (const char *str);                   
  248. unsigned _Cdecl   ComOut         (const void *abyte, unsigned n_byte); 
  249. unsigned _Cdecl   ComLenTx       (void);                       
  250. void     _Cdecl   ComFlushTx     (void);                       
  251.  
  252.  
  253.    /* status functions  */
  254.  
  255. void     _Cdecl   ComMcr         (byte on_off, byte bits);  
  256. unsigned _Cdecl   ComError       (void);                    
  257. byte     _Cdecl   ComStatus      (void);
  258.  
  259.  
  260.    /* misc fuctions  */
  261.  
  262. void     _Cdecl   ComSetBreak    (void);                    
  263. void     _Cdecl   ComClrBreak    (void);                    
  264. void     _Cdecl   ComPutScrtch   (byte abyte);              
  265. byte     _Cdecl   ComGetScrtch   (void);                    
  266.  
  267.  
  268. byte     _Cdecl   ComChecksum    (const void *abyte, unsigned n_byte);
  269. unsigned _Cdecl   ComCrc16       (const void *abyte, unsigned n_byte);
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.                               
  278.